import React from 'react'
import { Route, Redirect, useLocation } from 'react-router-dom'
import { hasToken } from '@/utils/storage'
export default function AuthRoute({ component: Component, ...rest }) {
  const location = useLocation()
  console.log(location)
  return (
    <Route
      {...rest}
      render={() => {
        if (hasToken()) {
          return <Component></Component>
        } else {
          return (
            <Redirect
              to={{
                pathname: '/login',
                from: location,
              }}
            ></Redirect>
          )
        }
      }}
    ></Route>
  )
}
